package trainingcamp.day01.SmallItme;
import java.util.Random;

public class 洗牌发牌算法 {
    public static void main(String[] args) {
        //获得一副牌
        String[] array = new String[54];
        String[] content ={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
        for(int i = 0;i < 13;i++){
            int a = i%13;
            array[a] = "黑桃"+content[i];
            array[a+13] = "红桃"+content[i];
            array[a+26] = "方块"+content[i];
            array[a+39] = "梅花"+content[i];
        }
        array[52] = "小王";
        array[53] = "大王";

        //将牌洗乱
        for(int i = 0;i < array.length;i++){
            Random random = new Random();
            int b = random.nextInt(53);
            String c = array[i];
            array[i] = array[b];
            array[b] = c;
        }

        //创造3名玩家
        String[] xiaoming = new String[17];
        String[] xiaohong = new String[17];
        String[] xiaozhang = new String[17];

        //发牌给三名玩家
        for(int i = 0; i<17;i++){
            xiaoming[i] = array[i*3];
            xiaohong[i] = array[i*3+1];
            xiaozhang[i] = array[i*3+2];
        }

        //地主牌三张
        System.out.println("地主牌三张:"+array[51]+array[52]+array[53]);

        System.out.println("xiaoming的手牌是:");
        for(int i = 0;i<17;i++){
            System.out.print(xiaoming[i]+" ");
        }
        System.out.println();
        System.out.println("xiaohong的手牌是:");
        for(int i = 0;i<17;i++){
            System.out.print(xiaohong[i]+" ");
        }
        System.out.println();
        System.out.println("xiaozhang的手牌是:");
        for(int i = 0;i<17;i++){
            System.out.print(xiaozhang[i]+" ");
        }
    }
}
